package com.secsbrain.cmdb.biz.utils;

import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;

public class UserUtils {

    /**
     * 获取租户编号
     */
    public static String getTenantCode(HttpServletRequest request){
        String tenantCode = parseFromHeaderOrParameter(request, "tenantCode");
        if(StringUtils.isNotEmpty(tenantCode)){
            return tenantCode;
        }else{
            return "DC";
        }
    }

    private static String parseFromHeaderOrParameter(HttpServletRequest request, String key) {
        String value = request.getHeader(key);
        return value == null ? request.getParameter(key) : value;
    }

}
